<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Porting extends CI_Controller {

  public function __construct()
  {
    parent::__construct();
    // $this->load->model('mglobal');
  }
  public function index()
  {

    $this->load->model('mporting');
    $table = $this->mporting->get_all_ds();

    foreach ($table as $tab) {
      $data = $this->mporting->jc($tab->table_name);

      // print_r($data);
      foreach ($data as $key) {
        $year = substr($key->yyyymm, 0, 4);
        $week = substr($key->yyyymm, 4, 2);
        $date_r = array($key->d1, $key->d2, $key->d3, $key->d4, $key->d5, $key->d6, $key->d7);
        $i = 1;
        foreach ($date_r as $d_val) {
          $doY = (($week*7)+($i-7));
          // echo $key->channel_id.' '.$key->yyyymm.' ';
          $m = date('m', strtotime("January 1st, ".$year." +".($doY)." days"));
          $d = date('j', strtotime("January 1st, ".$year." +".($doY)." days"));
          // echo '<br>';
          $this->mporting->do_port($key->sales_id, $key->channel_id, $year, $m, $d, $d_val);
          $i++;
        }
      }
    }
    // print_r($data);
  }

  public function test()
  {
    $doY = ((40*7)-(7-2));
    echo date('d-M-Y W', strtotime("January 1st, 2012 +".($doY-1)." days"));
    echo '<br>';
  }

}

/* End of file porting.php */
/* Location: ./application/controllers/porting.php */
